Array.prototype.contains = function(obj) {
  var i = this.length;
  while (i--) {
    if (this[i] === obj) {
      return true;
    }
  }
  return false;
}
Array.prototype.diff = function(B) {
	var arr = this.slice(0);
	for(var ix=this.length-1;ix>=0;ix--){
		if(B.contains(this[ix]))
			arr.splice(ix, 1);
	}
	return arr;
}

$(document).ready(function(){
	setModal("msgs","Mensaje");
});

function msg(texto,severity){
	//dsc: Esta función es para mostrar mensajes al usuario
	var img_src;
	switch(severity){
		case 'error':
			img_src = 'icon-error.gif';
			break;
		case 'warn':
			img_src = 'icon-warning.gif';
			break;
		case 'question':
			img_src = 'icon-question.gif';
			break;
		default:
			img_src = 'icon-info.gif';
			
	}
	var $msgs=$("#msgs");
	$msgs.find(".modal_cont").html('<img src="'+base_url+"images/window/"+img_src+'" style="margin: 0.5em; position: absolute;"><span style="position: absolute; margin-top: 1em; left: 55px;">'+texto+'</span>');
	$msgs.jqmShow()
}

function inpWaterMark(id,wtext){
	$("#"+id)
	.val(wtext).attr('empty','s')
	.focus(function(){
		if($(this).attr('empty')=='s'){
			this.value='';
			$(this).removeAttr('empty');
		}else this.select();
	}).blur(function(){
		if(this.value==''){
			$(this).attr('empty','s');
			this.value=wtext;
		}
	});
}

function sendPostAjax(opts){
	opts.type = 'POST';
	opts.url = base_url+opts.url;
	$.ajax(opts);
}

function setModal(id, title){
	var $id = $("#"+id);
	var html = 
		//title
		'<table class="title" width="100%" cellpadding="0" cellspacing="0"><tr><td class="left-title" width="10px"/><td class="middle-title">'+title+'<a class="jqmClose"><img src="'+base_url+'images/window/button-close-focus.gif"></a></td><td class="right-title" width="10px"></td></tr></table>'
		//middle
		+$id.html()
		//+'<table width="100%" cellpadding="0" cellspacing="0"><tr><td class="left-center" width="7px">&nbsp;</td><td>'+$id.html()+'</td><td class="right-center" width="7px"></td></tr>'
		//footer
		//+'<tr><td class="left-footer">&nbsp;</td><td class="middle-footer">&nbsp;</td><td class="right-footer">&nbsp;</td></tr>'
	;
	$("#"+id).html(html).jqm({modal: true});
}

